from abc import ABC, abstractmethod
from config_manager import ConfigManager
from device_manager import DeviceManager

class SerialDiskInterface(ABC):
    def __init__(self, config_path):
        self.config_manager = ConfigManager(config_path)
        config = self.config_manager.load()
        self.device_manager = DeviceManager(config)
        
    def _init_device_manager(self):
        """初始化设备管理器"""
        if not hasattr(self, 'device_manager') or self.device_manager is None:
            self.device_manager = DeviceManager()
            
        # 确保 transfer_manager 被正确初始化
        if hasattr(self.device_manager, 'transfer_manager'):
            self.device_manager.transfer_manager.register_callback(
                'progress', self.handle_transfer_progress)
            self.device_manager.transfer_manager.register_callback(
                'complete', self.handle_transfer_complete)
        
    @abstractmethod
    def start(self):
        """启动应用"""
        raise NotImplementedError()
        
    @abstractmethod
    def stop(self):
        """停止应用"""
        raise NotImplementedError()
        
    @abstractmethod
    def _handle_transfer(self, source_item, is_upload):
        """处理文件传输"""
        raise NotImplementedError()
        
    @abstractmethod
    def handle_transfer_progress(self, transferred, total, status=None):
        """处理传输进度"""
        raise NotImplementedError()
        
    @abstractmethod
    def handle_transfer_complete(self, success, error):
        """处理传输完成"""
        raise NotImplementedError()
        
    @abstractmethod
    def handle_device_error(self, error):
        """处理设备错误"""
        raise NotImplementedError()
